Const Statement

Declares a value as a local constant.


Syntax

Const constantname = value


Notes

The Const statement can be used in place of the Dim statement followed by an assignment statement when you are sure that the value of the variable should not change within the method. Using Const instead of Dim provides a convenient way to manage such values.

A Const statement can be placed anywhere in a method, including inside a conditional structure, such as an If statement, or a looping structure.

Constants declared in this manner are local to the method. You can also create constants in a window, class, or module. Constants that belong to windows or classes can be public (accessible throughout the application, protected (accessible only within the object that owns the constant and its subclasses), or private (accessible only within the object that owns it). Modules can have global constants, accessible throughout the application.


Examples

The following constant is used to set a button's caption.

Const Accept="OK"
BevelButton1.caption=Accept

The following sets the value of "Pi" for the method.

Const Pi=3.14159265358979323846264338327950

See Also

Dim statement.